/**
 * 
 *  true  : 测试环境
 *  false ：正式环境
 */
var isDebug = true;

var appData = {
  isLoading: false,
  HTMLURL: "", //图片地址
  APIURL: "", // 接口地址
  onlogin: false,
  txMapKey: "IJGBZ-U7O3G-2S5Q6-IXCU3-7MDDO-CEBDC",
  LoadDistance: 500,
  fission: false,
  tabIcon: {},
  /**
   * 接口地址
   */
  SERVICE: {
    "getlistall": "car/carManager/orderMain/list",
    "getListById": "car/carManager/orderMain/findById",
    "editOrder": 'car/carManager/orderMain/update',
    "carOrderClerkSave": 'car/carManager/orderClerk/save.do', //保存订单

    //接单员
    'findShopSkuById': 'car/carManager/shopSku/list',
    "coreWorkerShopSave": "usercenter/core/coreWorkerShop/save.do",
    "coreWorkerShopListAll": "usercenter/core/coreWorkerShop/listAll.do",

    /**
     * 用户相关接口
     */
    "htShareConfigListAll": "htShareConfig/listAll.do",
    "GetUserInfoByCode": "capi/xcx/login.do", // 根据code获取token
    // "GetUserInfoByCode": "usercenter/xcx/union/login.do", // 根据code获取token
    // "GetUserInfoByCode": "weapp/memberUser/login2.do", // 根据code获取token
    // "GetUserPhone": "weapp/memberUser/getPhoneNumbememberr.do", //获取手机号
    // "GetUserInfoByCode": "memberUser/loginV3.do", // 根据code获取token
    "memberUseredit": "capi/V2/recruitxcx/memberUser/update", //咨询用户信息、授权后存用户信息
    "MemberUserGetInfoById": "weapp/memberUser/getInfoById.do", // 获取用户信息
    "o2oToolsUpload": "weapp/o2oTools/upload.do", //咨询用户头像
    "applyBychannelId": "weapp/memberUser/levelOneApply.do", //申请为分销商
    "applyJunior": "weapp/memberUser/applyJunior.do", //申请推客
    "findChannel": "weapp/memberUser/isLevelOne.do", //判断是否是此店铺分销商
    "memberUserAddressList": "weapp/memberUserAddress/list.do", //查询用户的收货地址列表
    "memberUserAddressFindById": "weapp/memberUserAddress/findById.do", //根据地址Id查询某个地址
    "memberUserAddressSave": "weapp/memberUserAddress/save.do", //新增用户收货地址
    "memberUserAddressDel": "weapp/memberUserAddress/del.do", //删除用户收货地址
    "memberUserAddressUpdate": "weapp/memberUserAddress/update.do", //咨询用户收货地址
    "memberUserAddressSelectDefault": "weapp/memberUserAddress/selectDefault.do", //查询当前用户的默认收货地址
    "memberUserAddressSetDefault": "weapp/memberUserAddress/setDefault.do", //设置默认收货地址
    "memberUserAccount": "weapp/memberUserAccount/list.do", //用户余额
    "bindPhoneNumber": "weapp/memberUser/bindUserInfoJustMobile", //绑定手机号
    /**
     * 分销商的商品操作
     */
    "getByChannelId": "weapp/salesChannels/getByChannelId.do", //查询分销商的商品
    "addSku": "weapp/salesChannels/addSkuPlusLevelOne.do", //分销商上架商品
    "downSku": "weapp/salesChannels/downSku.do", //分销商下架商品
    "findTwoLevelTree": "weapp/category/findTwoLevelTree.do", //查询分销商所在店铺的所有二级分类
    "findBySalesNum": "weapp/salesChannels/findBySalesNum.do", //分销商信息
    "getCommission": "weapp/memberUserAccount/getCommission.do", //分销商个人中心信息查询
    "applyBychannelIdPlus": "weapp/memberUser/applyBychannelIdPlus.do", //疯狂英语分销商申请
    /****
     * 店铺有关接口
     * */
    "GetShopOneById": "weapp/shop/getShopOneById", //根据Id获取店铺信息
    'getShopNameById': 'weapp/shop/getShopNameById.do', //根据Id获取店铺名称
    'getShopTelById': 'weapp/shop/getShopTelById.do', //根据Id获取店铺联系方式
    "GetList": "weapp/shopCarouse/getList.do", // 获取店铺首页轮播图
    "getShopTemplate": "weapp/shopTemplate/getInfoByid2.do", //获取店铺模板详情
    "getByGroupId": "weapp/category/getByGroupId.do", //获取分组详情以及分类
    /**
     * 商品相关、商品分类
     */
    "getSecondLevelList": "weapp/category/getSecondLevelList.do", //获取店铺一级分类
    "GetshopSkuList": "weapp/shopSku/getshopSkuList.do", //根据二级类别id获取商品列表
    "getCategoryTreeList": "weapp/category/getByShopId.do", //获取一级二级分类树状结构
    "GetThreeLevelList": "weapp/category/getAllSecondList.do", // 根据一级类别ID获取二级类别
    "getShopSkuOne": "weapp/shopSku/getshopSkuOne.do", //根据商品的id获取商品详情
    /**
     * 购物车接口
     */
    "GetGoodsCartList": "weapp/goodsCart/getList.do", // 获取购物车列表
    "SaveGoodsCart": "weapp/goodsCart/saveGoodsCart.do", // 商品加入购物车
    "DelGoodsCart": "weapp/goodsCart/delGoodsCart.do", // 商品移出购物车
    "CheckOrCancelGoods": "weapp/goodsCart/checkOrCancelGoods.do", // 购物车中该商品是否选中
    "clearGoodsCart": "weapp/goodsCart/clearGoodsCart.do", //清空购物车
    /**
     * 订单有关接口
     */
    "GetOrderInfo": "weapp/order/getOrderInfo.do", // 订单列表
    "GetOrderDetailInfo": "weapp/order/getOrderDetailInfo.do", // 订单详情
    "CancelOrder": "weapp/order/cancelOrderV2.do", // 取消订单
    "DelOrder": "weapp/order/delOrder.do", // 删除订单
    "getartDetails": "car/carManager/article/list", //获取文章

    /**
     * 下单支付接口，包括未支付订单支付
     */
    "saveCarCard": "car/carManager/cardUser/save.do", //支付成功保存卡券入表
    "saveCarCardBatch": "car/carManager/cardUser/saveSameBatch", //支付成功保存卡包入表
    "saveCarCardJsonBatch": "car/carManager/cardUser/batchSave", //支付成功保存卡包入表
    "payByTimeCard": "weapp/order/payByTimeCard.do", //卡券支付
    "SaveOrder": "weapp/order/saveOrderV5.do", //生成订单
    // "SaveOrder": "capi/V2/orderV2/orderDetail/save", //生成订单
    "buyWeChatLitOnline": "weapp/weChatRechargeLit/buyWeChatLitOnlineV5.do", //根据订单号获取支付信息
    "updateOrderPay": "weapp/order/updateOrderPay.do", //下单后未支付成功，待支付状态支付时获取支付信息
    "getOneById": "weapp/order/getOneById.do", //支付成功后查询订单详情
    "buyWeChatLitOnlineV6": "weapp/weChatRechargeLit/buyWeChatLitOnlineV6.do", //单纯的支付功能
    /**
     * 生成分销二维码
     */
    "getlitPicture": "weapp/memberShop/litPicture.do", //根据参数生成小程序码
    "getSkulitPicture": "weapp/memberShop/litPictureV2.do", //生成商品二维码
    "teamPersonNum": "weapp/salesChannels/teamPersonNum.do", //分销商的推客总人数
    "getOrderTotalAccountByShop": "weapp/order/getOrderTotalAccountByShop.do", //分销商总订单收入
    "getCountSubordinate": "weapp/salesChannels/countSubordinateAll.do", //查询下级分销商人数
    "getCountSubordinateOrder": "weapp/salesChannels/countSubordinateOrder.do", //查询下级销售订单量
    "getTodayOrderNumSumMoney": "weapp/salesChannelsRecord/getTodayOrderNumSumMoney.do", //分销商今日收益以及订单
    "salesChannelsRecordlist": "weapp/salesChannelsRecord/list", //佣金记录
    /*
     *栏目文章
     */
    "getCaseList": "weapp/channelAk/getListByShop.do", //获取shop下的所有栏目(分页)
    "getArticleList": "weapp/Article/listByChannel.do", //获取shop中指定栏目中文章(分页)
    "getArticleListAll": "weapp/Article/listByShop.do", //获取shop全部栏目中文章(分页)
    "getDetails": "weapp/Article/findById.do", //根据id获取文章

    "getInformationBrand": "car/carManager/ghyxCarBrand/listAllGroupLetter.do", //获取品牌列表,
    "getInfomationBrandName": "car/carManager/ghyxCarBrand/list", //根据brand_name获取信息
    /*     "getInfomationCarConfig":"car/carManager/ghyxCarConfig/listAll.do",//根据carconfig获取信息
     */
    "ghyxCarListAll": "car/carManager/ghyxCar/list", //获取品牌列表
    "carColorListAll": "car/carManager/carColor/listAll.do", //获取颜色列表
    "carMainListAll": "car/carManager/carMain/listAll.do", //获取车列表
    "carMainSave": "car/carManager/carMain/save.do", //保存车信息
    "carMainUpdate": "car/carManager/carMain/update.do", //咨询车信息
    "carMainDel": "car/carManager/carMain/del.do", //删除车信息

    "getCardList": "car/carManager/cardUser/findById", //根据ID获取卡卷
    "getCardListAll": "car/carManager/cardUser/list", //获取全部卡卷列表
    "getCardListAllTotal": "car/carManager/cardUser/listAll", //获取全部卡卷列表
    "getCardUpdate": "car/carManager/cardUser/update", //获取全部卡卷列表

    "getFisrtList": "car/carManager/firstOrder/listAll", //获取首单列表
    "saveFirstInfo": "car/carManager/firstOrder/save", //保存首单信息
    "saveCarInfo": "car/carManager/carOrder/save", //保存订单信息
    "getCarInfo": "car/carManager/carOrder/listAll", //获取全部订单列表
    "getDutyTime": "car/carManager/workTimeSetting/list",
    "getcardsku": 'shop/shopCategory/getByShopId.do', //获取卡圈分类
    "salesQuotation": 'sales/salesManager/salesQuotation/save', //生成报价单
    "getshop": 'usercenter/shopArea/businessShop/list',
    "getshopAll": 'usercenter/shopArea/shop/listAll',
    "getShopListBylocation": 'weapp/shop/getShopListBylocation',
    "getsalesuserchannellist": 'sales/salesManager/userChannel/list', //查询上级分销商
    "savesalesuserchannel": 'sales/salesManager/userChannel/save', //保存上级分销商
    "giftPackageList": 'sales/salesManager/giftPackage/list', //查询发红包
    "giftPackageSave": 'sales/salesManager/giftPackage/save', //保存礼包
    "giftRecordSave": 'sales/salesManager/giftRecord/getGift', //添加领卡记录
    "giftRecordList": 'sales/salesManager/giftRecord/listAll', //保存领卡记录
    "getAccountRecordList": 'sales/salesManager/memberUserAccountRecord/list',
    "getsalesuserchannellistwith": 'sales/salesManager/userChannel/listWithUserInfo',
    "orderComplaintsSave": 'car/carManager/orderComplaints/save', //保存投诉信息

    "carOrderMainUpdate": 'car/carManager/orderMain/update.do', //咨询订单状态
    "getTrandeList": 'car/carManager/shopCategory/listAll', //获取行业
    'saveshop': 'console/shopInfo/save.do', //保存店铺
    'savebusiness': 'usercenter/shopArea/businessShop/save', //保存店铺
    'getAddress': 'console/shopInfo/address.do',
    'gettableScreen': 'car/carManager/tableScreen/list' //获取插屏
  },
  getAjax: function (url, data, fn) {
    this.getAjaxUrlValueBackground(this.SERVICE[url], data, fn)
  },
  getAjaxUrlValue: function (url, data, fn) {
    this.getAjaxUrlValueBackground(url, data, fn)
  },
  
  getAjaxUrlValueBackground: function (url, data, fn) {
    this._getAjaxUrlValueBackground(url, data, fn, true)
  },
  getAjaxUrlValueBackgroundWidthFailbc: function (url, data, fn, failbc) {
    this._getAjaxUrlValueBackground(url, data, fn, true, failbc)
  },
  //数据请求
  _getAjaxUrlValueBackground: function (url, data, fn, isBackground, failbc) {
    var that = this;
    // 加载model
    if (!isBackground) {
      wx.showLoading({
        title: '加载中...',
      })
    }
    let token = wx.getStorageSync("token")
    // 添加版本控制 
    var arrData = {
      logs_shop_id:getApp().globalData.shop_id,
      logs_business_id: getApp().globalData.business_id,
      logs_user_id: wx.getStorageSync('user_id'),
      logs_client:1,
      version: that.VERSION,
      business_id: that.businessId,
      shop_id: wx.getStorageSync('shop_id') ? wx.getStorageSync('shop_id') : that.shopId,
      user_id: wx.getStorageSync('user_id'),
      ...data,
      token: token
    }

    if (getApp().globalData.config_business_id) {
      arrData.config_business_id = getApp().globalData.config_business_id
    }
    if (data.user_id == '' || data.user_id == "") {
      delete arrData.user_id;
    }
    if (data.shop_id == '' || data.shop_id == "") {
      delete arrData.shop_id;
    }

    // console.log(that.APIURL + that.SERVICE[url])
    // console.log(arrData)
    // 
    wx.request({
      url: that.APIURL + url,
      data: arrData,
      method: "GET",
      success: function (res) {
        wx.hideLoading();
        // typeof fn == "function" && fn(res);
        if (res.data.success) {
          if (res.data.data) {
            typeof fn == "function" && fn(res.data.data);
          } else if (res.data) {
            typeof fn == "function" && fn(res.data);
          } else {
            typeof fn == "function" && fn(res);
          }
        } else {
          if (failbc) {
            typeof fn == "function" && fn(res.data);
            return;
          }
          if (res.data && res.data.token) {
            typeof fn == "function" && fn(res.data);
            return;
          }
          if (res.data.msg && res.data.msg != '') {
            wx.showToast({
              title: res.data.msg,
              icon: "none",
              duration: 3000,
            })
          }
        }
      },
      fail: function (XMLHttpRequest) {
        wx.hideLoading();
  
        console.log(XMLHttpRequest)
        wx.showToast({
          title: "网络连接超时",
          icon: 'error',
          duration: 2000
        })
      },
      complete: function (res) {
        // wx.hideLoading();
      }
    });
  },
}
var onInit = function () {


  if (isDebug) {
    appData.HTMLURL = "https://apicar.iloomo.com/"; //图片访问地址
    // appData.APIURL = "https://weapp.linglingshenghuo.com/";//测试环境
    appData.APIURL = "https://apicar.iloomo.com/"; //测试环境
  } else {
    appData.HTMLURL = "https://api.iloomo.com/"; //图片访问地址
    appData.APIURL = "https://api.iloomo.com/"; //正式环境
  }
  appData.HTMLURL = "https://test.iloomo.com/"; //图片访问地址
  appData.APIURL = "https://test.iloomo.com/"; //正式环境
  return appData;
};
module.exports = onInit();